package com.example.hello.controller;

import com.example.hello.mapper.BookMapper;
import com.example.hello.pojo.*;
import com.example.hello.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;


    /**
     * 根据id删除图书
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Res deleteById(@PathVariable Integer id) {
        log.info("要删除的图书id为：{}",id);
        adminService.deleteById(id);
        return Res.success();
    }

    /**
     * 更新图书信息
     */
    @PutMapping("/update")
    public Res update(@RequestBody Book book) {
        log.info("修改的图书信息为{}",book);
        adminService.update(book);
        return Res.success();
    }

    /**
     * 查询用户借书情况
     */
    @GetMapping("/userInfoList")
    public Res findUserBorrowInfo(
            PageQueryParam pageQueryParam
    ){
        PageResult<UserBorrowBookInfo> userBorrowBookInfoList = adminService.findUserBorrowInfoList(pageQueryParam);
        log.info("正在查询所有用户的图书借阅情况");
        return Res.success(userBorrowBookInfoList);
    }

    /**
     * 修改用户状态
     */
    @PutMapping("/updateUserStatus")
    public Res updateUserStatus(
            @RequestParam("id") Integer id,
            @RequestParam("status") Integer status
    ){
        log.info("将用户id为{}，的状态设置为{}",id,status);
        adminService.updateUserStatus(id,status);
        return Res.success();
    }
}
